package com.yopinclub.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yopinclub.R;
import com.yopinclub.entity.Picture;
import com.yopinclub.resloader.ImageDownloadTask;

public class StreamAdapter extends BaseAdapter {

	private List<Picture>	mPictures;
	private Context			mContext;

	public StreamAdapter(List<Picture> pictures, Context context) {
		this.mPictures = pictures;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return mPictures.size();
	}

	@Override
	public Object getItem(int position) {
		return mPictures.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = ((Activity) mContext).getLayoutInflater().inflate(R.layout.item_stream, null);
		}
		final ImageView picture = (ImageView) convertView.findViewById(R.id.img_picture);
		picture.setImageResource(R.drawable.suggested_imagecell);
		new ImageDownloadTask() {

			public void imageDownloadComplete(android.graphics.Bitmap bitmap) {
				picture.setImageBitmap(bitmap);
			};
		}.execute(mPictures.get(position).getPicturePath());

		TextView tvTitle = (TextView) convertView.findViewById(R.id.tv_title);
		tvTitle.setText(mPictures.get(position).getQuestion());
		TextView tvContent = (TextView) convertView.findViewById(R.id.tv_content);
		tvContent.setText("1h");
		return convertView;
	}

	public void setPictures(List<Picture> mPictures) {
		this.mPictures = mPictures;
	}

}
